﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PodpisyElektorniczne.Interfaces;

namespace PodpisyElektorniczne
{
    public partial class frmReginstration : Form
    {
        private LoggedIn log;
        public frmReginstration()
        {
            log = new LoggedIn();
            InitializeComponent();
            log = Program.Log;
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (!ValidateFields())
                return;
            else
            {
                if (log.TryToRegister(txt_login.Text.Trim(), txt_name.Text.Trim(), txt_surname.Text.Trim(),
                                  txt_email.Text.Trim(), txt_pass.Text.Trim()))
                {
                    Program.Ll.Show();
                    this.Close();
                   
                }
            }

        }

        private bool ValidateFields()
        {
            DefaultVals();
            bool valid = true;
            if (txt_login.Text == String.Empty)
            {
                val_login.Visible = true;
                valid = false;
            }
            if (txt_name.Text == String.Empty)
            {
                val_name.Visible = true;
                valid = false;
            }
            if(txt_surname.Text == String.Empty )
            {
                val_surn.Visible = true;
                valid = false;
            }
            if(txt_email.Text == String.Empty)
            {
                val_email.Visible = true;
                valid = false;
            }
            if(txt_pass.Text == String.Empty)
            {
                val_pass.Visible = true;
                valid = false;
            }
            else if (txt_pass.Text != txt_confi.Text)
            {
                val_pass.Visible = true;
                valid = false;
            }

            if(txt_confi.Text == String.Empty)
            {
                val_conf.Visible = true;
                valid = false;
            }
           
            return valid;
        }


        public void DefaultVals()
        {
            val_name.Visible = false;
            val_surn.Visible = false;
            val_email.Visible = false;
            val_pass.Visible = false;
            val_conf.Visible = false;
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
